package com.nf.health.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nf.health.app.R;
import com.nf.health.app.models.RecommendSport;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

public class DoctorRecomSportAdapter extends BaseAdapter {

	private Context context;
	private List<RecommendSport> doctorRecomSportList;
	public DoctorRecomSportAdapter(Context context, List<RecommendSport> doctorRecomSportList) {
		this.context = context;
		this.doctorRecomSportList = doctorRecomSportList;
	}
	
	@Override
	public int getCount() {
		if(doctorRecomSportList != null){
			return doctorRecomSportList.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		return doctorRecomSportList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_healthy_plan, position);
		RecommendSport sport = doctorRecomSportList.get(position);
		ImageView sport_icon = holder.getView(R.id.sport_icon);
		holder.setText(R.id.sport_name, sport.getName());
		holder.setText(R.id.sport_suit_type, sport.getDesc());
		ImageView hold_finish = holder.getView(R.id.hold_finish);
		ImageLoaderUtils.getinstance(context).getImage(sport_icon, sport.getImg(), R.drawable.new_default_nf_icon);
		if (!TextUtils.isEmpty(sport.getStatus())) {
			if ("n".equals(sport.getStatus())) {
				hold_finish.setBackgroundResource(R.drawable.new_hold_finish);
			} else if ("y".equals(sport.getStatus())) {
				hold_finish.setBackgroundResource(R.drawable.home_state_two);
			}
		} else {
			hold_finish.setBackgroundResource(R.drawable.home_add_hplan);
		}
		hold_finish.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				listener.onClick(position, DoctorRecomSportAdapter.class.getSimpleName());	
			}
		});
		return holder.getConvertView();
	}
	private OnMyClickListener listener;
	public void setOnMyClickListener(OnMyClickListener listener) {
		this.listener = listener;
	}

}
